package cn.tannn.surenessdemo.user.service;

import cn.tannn.surenessdemo.redis.service.RedisService;
import com.usthe.sureness.matcher.TreePathRoleMatcher;
import org.springframework.stereotype.Service;

/**
 * TreePathRoleMatcher的补充
 *
 * @author tnnn
 * @version V1.0
 * @date 2022-07-22 18:50
 */
@Service
public class TreePathRoleMatcherService {

    private final TreePathRoleMatcher treePathRoleMatcher;
    private final RedisService redisService;

    public TreePathRoleMatcherService(TreePathRoleMatcher treePathRoleMatcher,
                                      RedisService redisService) {
        this.treePathRoleMatcher = treePathRoleMatcher;
        this.redisService = redisService;
    }

    /**
     * 资源修改时进行刷新数据库到redis
     * - 不需要拦截的资源数据
     * - 需要拦截的资源数据
     */
    public void rebuildTree(){
        // 不需要拦截的资源数据
        redisService.loadDisableResourceMysqlLoad();
        // 需要拦截的资源数据
        redisService.loadEnableResourceMysqlLoad();
        treePathRoleMatcher.rebuildTree();
    }

    /**
     * 每次接口请求就拉取redis到本地缓存
     */
    public void rebuildTreeRepetition(){
        treePathRoleMatcher.rebuildTree();
    }
}
